package cn.ilikes.tools.nosql.jpa.clients.indexs;

import java.util.List;
import java.util.Properties;

import cn.ilikes.tools.nosql.jpa.graphs.Node;
import cn.ilikes.tools.nosql.jpa.metadatas.EntityMetaData;
import cn.ilikes.tools.nosql.jpa.query.HQueryImpl.SQLQueryType;
import cn.ilikes.tools.nosql.jpa.query.pages.PageEntitys;

public interface IClientIndex {

	public int INVALID = -1;

	public int NULL = -2;

	/** The Constant DELIMETER. */
	public static final String DELIMETER = "~";

	/** The Constant ENTITY_ID_FIELD. */
	public static final String ENTITY_ID_FIELD = "entity.id";

	/** The Constant JAPQL_ID_FIELD. */
	public static final String JPA_SQL_ID_FIELD = "jpa.sql.entity.id";

	public static final String ENTITY_INDEX_TIMESAMP = "entity.index.timestamp";

	/** The Constant ENTITY_INDEXNAME_FIELD. */
	public static final String ENTITY_INDEXNAME_FIELD = "entity.index.name";

	/** The Constant ENTITY_CLASS_FIELD. */
	public static final String ENTITY_CLASS_FIELD = "entity.class";

	public static final String index_fields_null = "null";

	/**
	 * auto ; 自动提交 manual 手动
	 * 
	 * @author fack
	 * 
	 */
	public enum FlushType {
		auto, manual
	}

	public enum IndexType {
		lucene,hadoop_lucene,asy_hadoop_lucene
	}

	public void init();

	public void close();

	public void flush();

	public boolean isOpen();

	public void rollback();

	/**
	 * 创建唯一索引
	 * 
	 * @param metadata
	 * @param entity
	 * @throws IndexingException
	 */
	public void create(Node node) throws ClientIndexingException;

	public void remove(Node node) throws ClientIndexingException;

	public void remove(EntityMetaData entityMetaData, Object key) throws ClientIndexingException;

	public boolean exist(EntityMetaData entityMetaData, Object key) throws ClientIndexingException;

	public boolean exist(Node node) throws ClientIndexingException;

	public abstract void update(Node node) throws ClientIndexingException;

	public abstract <V> List<V> search(String query, EntityMetaData metadata, int firstResult, int howMany) throws ClientIndexingException;

	public abstract PageEntitys searchPage(String query, EntityMetaData metadata, Properties properties, int howMany) throws ClientIndexingException;

	public abstract <V> List<V> search(String query, EntityMetaData metadata) throws ClientIndexingException;

	public abstract long searchSize(String query) throws ClientIndexingException;

	public abstract <V> List<V> search(String fields, String value) throws ClientIndexingException;

	public long selectSizeByKeyId(Object keyId, EntityMetaData metadata) throws ClientIndexingException;

}
